package SV_SENSITIVE_OBJ;
import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.security.Key;
public class Fixed_02 {
    public static class Writer {
        private String transformation = "AES/ECB/PKCS5Padding";
        public void writePatientInfo(OutputStream os, Patient patient, Key key)
                throws GeneralSecurityException, IOException {
            Cipher cipher = Cipher.getInstance(transformation);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            try (CipherOutputStream cos = new CipherOutputStream(os, cipher);
                 ObjectOutputStream oos = new ObjectOutputStream(cos)) {
                oos.writeObject(patient);
            }
        }
        public static class Patient {
            public String getName() { return "John Doe"; }
            public String getDob() { return "1900-01-01"; }
            public String getAddress() { return "123 Main St., Cityville, NY 12345"; }
        }
    }
}
